<template>
	<div class="page" style="background-color: #82e2ea;">
		<div class="weui-form">
			<div class="weui-form__text-area">
				<h2 class="weui-form__title">教员登录</h2>
			</div>
			<div class="weui-form__control-area">
				<div class="weui-cells__group weui-cells__group_form">
					<div class="weui-cells weui-cells_form">
						<div class="weui-cell weui-cell_active">
							<div class="weui-cell__hd">
								<label class="weui-label fl">姓名</label>
							</div>
							<div class="weui-cell__bd">
								<input class="weui-input" v-model="searchParam.name" placeholder="请输入姓名" />
							</div>

						</div>
						<div class="weui-cell weui-cell_active">
							<div class="weui-cell__hd">
								<label class="weui-label fl">工号</label>
							</div>
							<div class="weui-cell__bd">
								<input class="weui-input" v-model="searchParam.account" placeholder="请输入姓名" />
							</div>
						
						</div>
						<div class="weui-cell weui-cell_active weui-cell_vcode">
							<div class="weui-cell__hd">
								<label class="weui-label fl">手机号</label>
							</div>
							<div class="weui-cell__bd">
								<input class="weui-input" type="text" pattern="[0-9]*" v-model="searchParam.phone"
									placeholder="输入手机号" maxlength="6" />
							</div>

						</div>
						<div class="weui-cell weui-cell_active weui-cell_vcode">
							<div class="weui-cell__hd">
								<label class="weui-label  fl">输入验证码</label>
							</div>
							<div class="weui-cell__bd">
								<input class="weui-input" type="text" v-model="code" placeholder="输入验证码"
									maxlength="6" />
							</div>
							<div class="weui-cell__bd">
								<Code></Code>
							</div>
						</div>

					</div>

				</div>
			</div>
			<div class="weui-form__tips-area">
				<label id="weuiAgree" for="weuiAgreeCheckbox" class="weui-agree">
					<input id="weuiAgreeCheckbox" type="checkbox" v-model="searchParam.isSuper" class="weui-agree__checkbox" /><span
						class="weui-agree__text">超级管理员</a>
					</span>
				</label>
			</div>
			<div class="weui-form__opr-area">

				<a class="weui-btn weui-btn_primary green" @click="schoolLogin" id="showTooltips">登录</a>

			</div>
		</div>
	</div>
</template>

<script>
	import Code from '@/conpon/code.vue'
	import constant from '@/utils/constant';
	import uwLoadJs from '@/utils/uwLoad'
	import urls from '@/utils/apis'
	import {
		getToken,
		setToken,
	} from '@/utils/auth'
	export default {
		name: "home",
		components: {
			Code
		},
		data() {
			return {
				searchParam:{
					name: '', //老师姓名
					phone: '', //老师手机号
					position:'1',//是否超级管理员
				},
				code: '',
				original_vcode:'',
			}
		},
		mounted() {
			
		},
		created() {
			document.title = '员工登录';
			
		},
		methods: {
			//图形吗
			setOriginCode(code){
				this.original_vcode = code;
			},
			schoolLogin() {
				if (this.searchParam.username == '') {
					this.showMsg(null, "姓名")
					return
				}
				if (this.searchParam.phone == '') {
					this.showMsg(null, "手机号")
					return
				}
				if (this.code == '') {
					this.showMsg(null, "验证码")
					return
				}
				if(this.searchParam.isSuper == true) {
					this.searchParam.position = "A";
				}
				// if (identifyCode != this.code) {
				// 	this.showMsg("验证码输入有误")
				// } 
				localStorage.clear();
				let res = uwLoadJs.ajaxRequest(this.searchParam, urls.techLogin);
				if (res.resultCode == constant.SUCCESS && res.data != null) {
					this.showMsg("登录成功！", null, "success");
					let data = res.data;
					const token = data.token;
					var inFifteenMinutes = new Date(new Date().getTime() +  30 * 60 * 1000);
					localStorage.setItem(constant.YS_TOKEN, token)
					localStorage.setItem(constant.TOKEN, token)
					localStorage.setItem(token, JSON.stringify(data))
					localStorage.setItem('userInfo', JSON.stringify(data.userInfo))
					this.$router.replace({path:'/techManagerMain'});
				} else {
					this.showMsg("登录失败！", null, "danger");
				}

			},
			showMsg(text, msg, type) {
				this.$toast({
					text: text || '请输入' + msg + "!",
					type: type || 'warning',
					duration: 1000
				});

			},
		},
	}
</script>

<style>
	.fl {
		text-align: left;
	}

	.close {
		width: 25px;
		height: 25px;
		position: absolute;
		top: 25px;
		left: 25px;
		background-size: 100%;
	}

	.green {
		color: green;
	}

	.weui-cells__group_form .weui-cell__hd {
		padding-right: 10px;
	}
</style>
